package com.mms.pojo;

import org.hibernate.annotations.*;
import org.hibernate.annotations.Cache;
import javax.persistence.*;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

/**
 * Created by dangz on 2017/5/18/018.
 */
@Entity
@Table(name = "sys_operate")
//@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class SysOperate implements Serializable {
    private SysRoleOperate id;
    private SysMenu sysMenu;
    private String op;
    private String name;
    private String url;
    private String icon;
    private Integer orderNo;
    private Integer isShow;
    private Set<SysRole> sysRoles = new HashSet<SysRole>(0);

    @EmbeddedId
    @AttributeOverrides({
    @AttributeOverride(name = "menu", column = @Column(name = "MENU", nullable = false)),
    @AttributeOverride(name = "op", column = @Column(name = "OP", nullable = false, length = 50)) })
    public SysRoleOperate getId() {
        return id;
    }

    public void setId(SysRoleOperate id) {
        this.id = id;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "MENU", nullable = false, insertable = false, updatable = false)
    public SysMenu getSysMenu() {
        return sysMenu;
    }

    public void setSysMenu(SysMenu sysMenu) {
        this.sysMenu = sysMenu;
    }

    @Column(name = "op")
    public String getOp() {
        return op;
    }

    public void setOp(String op) {
        this.op = op;
    }

    @Column(name = "name")
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Column(name = "url")
    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    @Column(name = "icon")
    public String getIcon() {
        return icon;
    }

    public void setIcon(String icon) {
        this.icon = icon;
    }

    @Column(name = "orderNo")
    public Integer getOrderNo() {
        return orderNo;
    }

    public void setOrderNo(Integer orderNo) {
        this.orderNo = orderNo;
    }

    @Column(name = "isshow")
    public Integer getIsShow() {
        return isShow;
    }

    public void setIsShow(Integer isShow) {
        this.isShow = isShow;
    }

    @ManyToMany(cascade = CascadeType.PERSIST, fetch = FetchType.LAZY)
    @JoinTable(name = "sys_role_operate", joinColumns = { @JoinColumn(name = "MENU", nullable = false, updatable = false), @JoinColumn(name = "OP", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "ROLE", nullable = false, updatable = false) })
    public Set<SysRole> getSysRoles() {
        return this.sysRoles;
    }

    public void setSysRoles(Set<SysRole> sysRoles) {
        this.sysRoles = sysRoles;
    }
}
